package com.android.presenter.info;

import com.android.model.entity.res.SendCodeResult;
import com.android.model.net.HttpObserver;
import com.android.presenter.base.BasePresenter;
import com.android.model.info.UserModel;
import com.android.presenter.iview.ISendCodeView;
import com.android.util.log.LogUtil;

/**
 * author:  TenFace
 * date:    2017/9/27
 * description: 发送验证码
 */

public class SendCodePresenter extends BasePresenter<ISendCodeView> {

    private static final String TAG = SendCodePresenter.class.getSimpleName();
    private UserModel mUserModel;

    public SendCodePresenter(ISendCodeView iSendCodeView) {
        super(iSendCodeView);
        mUserModel = UserModel.getInstance();
    }

    public void sendSmsCode(String ex55Pin,String phone, String codeType, String operateType) {
        mUserModel.sendSmsCode(ex55Pin,phone, codeType, operateType, new HttpObserver<SendCodeResult>() {
            @Override
            public void onSuccess(SendCodeResult sendCodeResult) {
                LogUtil.e(TAG, "发送验证码成功！");
                if (mIView != null) {
                    mIView.sendCodeSuccess(sendCodeResult);
                }
            }

            @Override
            public void onError(int errType, String errMessage) {
                LogUtil.e(TAG, "发送验证码失败：" + errType + "--信息：" + errMessage);
                if (mIView != null) {
                    mIView.sendCodeFail(errType, errMessage);
                }
            }
        }, mIView.getLifeSubject());
    }

}
